package com.sgb.kjwl.viewmodel.pick;

import android.app.Application;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.pick.TenderDictEntity3;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.pick.TenderInquiryType;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 招标详情-补遗，详情
 */
public class PickTenderInquiryModel extends AndroidViewModel {

    public MutableLiveData<Boolean> dialog = new MutableLiveData<>();
    public MutableLiveData<String> showToast = new MutableLiveData<>();
    public MutableLiveData<List<TenderInquiryType>> tenderInquiryList = new MutableLiveData<>();
    public MutableLiveData<List<List<TenderDictEntity3>>> tenderDetailList = new MutableLiveData<>();
    public ObservableField<Integer> page = new ObservableField<>(1);

    public PickTenderInquiryModel(@NonNull Application application) {
        super(application);
    }

    //新增函询分页列表接口
    public void findTenderInquiryPage(String markId) {
        dialog.setValue(true);
        HashMap map = new HashMap();
        map.put("pageNum", page.get());
        map.put("pageSize", 10);
        map.put("markId", markId);
        APIManager.getInstance().getPickAPI().findTenderInquiryPage(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<TenderInquiryType>>>>() {

            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<TenderInquiryType>>> data) {
                if (data.getState().equals(AppConstant.REQEUST_SECCUESS)) {
                    tenderInquiryList.setValue(data.getData().getList());
                } else {
                    if (!TextUtils.isEmpty(data.getMsg())) {
                        showToast.setValue(data.getMsg());
                    }
                }
            }
        });

    }

    //新增清单分页列表接口
    public void findDetailGoodsPage(String id, int page) {
        dialog.setValue(true);
        Map map = new HashMap();
        map.put("tenderNo", id);
        map.put("page", page);
        map.put("limit", 10);
        APIManager.getInstance().getPickAPI().getGoodsPageVO(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<List<TenderDictEntity3>>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<List<TenderDictEntity3>>>> data) {
                if (data.getState().equals(AppConstant.REQEUST_SECCUESS)) {
                    tenderDetailList.setValue(data.getData().getList());
                } else {
                    if (!TextUtils.isEmpty(data.getMsg())) {
                        showToast.setValue(data.getMsg());
                    }
                }
            }
        });
    }
}
